package com.catt.orderdinner.service;

import com.catt.orderdinner.dataobject.TbFood;
import com.catt.orderdinner.repository.TbFoodRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodService {

    @Autowired
    private TbFoodRepository tbFoodRepository;

    public List<TbFood> findAll(){
        List<TbFood> all = tbFoodRepository.findAll();
        return all;
    }

    public Page<TbFood> findAll(Pageable pageable) {
        Page<TbFood> allFoodList = tbFoodRepository.findAll(pageable);
        return allFoodList;
    }

    public TbFood findOneByFoodId(String id){
        return tbFoodRepository.findOneByFoodId(id);
    }

    public void save(TbFood food){
        tbFoodRepository.save(food);
    }

    public void del(String id){
        tbFoodRepository.deleteById(id);
    }
}
